package
{
	import com.sina.microblog.MicroBlog;
	import com.sina.microblog.data.MicroBlogStatus;
	import com.sina.microblog.data.MicroBlogUser;
	import com.sina.microblog.events.MicroBlogEvent;
	
	import data.BlogUser;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class BlogManager extends MicroBlog
	{
		private static var _instance:BlogManager;
		private var _self:BlogUser;
		public function BlogManager(forcer:SingletonFocer)
		{
			super();
			source = "2304859517";
			initEvents();
		}
		
		private function initEvents():void
		{
			addEventListener(MicroBlogEvent.VERIFY_CREDENTIALS_RESULT,onLoginSeccess);
			addEventListener(MicroBlogEvent.LOAD_USER_TIMELINE_RESULT,onLoadMessage);
		}
		
		private function onLoadMessage(evt:MicroBlogEvent):void
		{
			var messages:Array = evt.result as Array;
			for each(var message:MicroBlogStatus in messages)
			{
				_self.Messages.push(message);
			}
		}
		
		private function onLoginSeccess(evt:MicroBlogEvent):void
		{
			_self = new BlogUser(evt.result.User);
		}
		
		public function get Self():BlogUser
		{
			return _self;
		}
		
		public static function get Instance():BlogManager
		{
			if(_instance == null) _instance = new BlogManager(new SingletonFocer());
			return _instance;
		}
	}
}

class SingletonFocer{}